package _021_10_5

import "sort"

type childArr [][]int

func (c childArr) Len() int {
	return len(c)
}

func (c childArr) Less(i, j int) bool {
	if len(c[i]) < len(c[j]) {
		return true
	}

	if len(c[i]) == len(c[j]) {
		for k := 0; k < len(c[i]); k++ {
			if c[i][k] == c[j][k] {
				continue
			}
			if c[i][k] < c[j][k] {
				return true
			}
			return false
		}
	}
	return false
}

func (c childArr) Swap(i, j int) {
	temp := c[i]

	c[i] = c[j]

	c[j] = temp
}

func subsets(A []int) [][]int {
	var result childArr
	result = append(result, []int{})
	for i := 0; i < len(A); i++ {
		size := len(result)
		for j := 0; j < size; j++ {
			temp := make([]int, 0)
			temp = append(temp, result[j]...)
			temp = append(temp, A[i])
			result = append(result, temp)
		}
	}
	sort.Sort(result)
	return result
}
